﻿<kt:KinectControl x:Class="Microsoft.Samples.Kinect.WpfViewers.KinectSettings"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:kt="clr-namespace:Microsoft.Samples.Kinect.WpfViewers"
             mc:Ignorable="d"
             d:DesignHeight="180" d:DesignWidth="220">
    <kt:KinectControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="KinectControlResources.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </kt:KinectControl.Resources>

    <StackPanel x:Name="ViewModelRoot" Orientation="Vertical">

        <!-- Not visible, this control will manage choosing skeletons -->
        <kt:KinectSkeletonChooser x:Name="SkeletonChooser" KinectSensorManager="{Binding KinectSensorManager}"/>

        <RadioButton Tag="_Color Stream" Style="{StaticResource KinectSettingsPanel}" Margin="0 0 0 10">
            <ListBox
                Style="{StaticResource KinectRadioList}"
                ItemsSource="{Binding ColorModes}"
                SelectedItem="{Binding SelectedColorMode}"/>
        </RadioButton>

        <RadioButton Tag="_Exposure Settings" Style="{StaticResource KinectSettingsPanel}" Margin="0 0 0 10"
                     Visibility="{Binding Path=KinectSensorManager.SupportsCameraSettings, Converter={StaticResource BoolToVisibilityConverter}}">
            <Grid Width="220">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="95"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>

                <TextBlock  Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right"
                    Text="Auto Exposure" Margin="0,0,10,0"
                    Style="{StaticResource KinectTextBlock}"/>
                <ListBox Margin="0,0,10,0" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"
                    Style="{StaticResource KinectRadioList}"
                    ItemsSource="{Binding ToggleStates}"
                    SelectedItem="{Binding Path=KinectSensorManager.CameraSettings.AutoExposure, Converter={StaticResource BoolToToggleStateConverter}}"/>

                <TextBlock  Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right"
                    Text="Brightness"  Margin="0,0,10,0"
                    Style="{StaticResource KinectTextBlock}"
                    IsEnabled="{Binding Path=KinectSensorManager.CameraSettings.AutoExposure}"/>
                <Slider  Grid.Row="1" Grid.Column="1" VerticalAlignment="Center"
                    Minimum="{Binding Path=KinectSensorManager.CameraSettings.MinBrightness}"
                    Maximum="{Binding Path=KinectSensorManager.CameraSettings.MaxBrightness}"
                    Value="{Binding Path=KinectSensorManager.CameraSettings.Brightness}"
                    IsEnabled="{Binding Path=KinectSensorManager.CameraSettings.AutoExposure}"
                    LargeChange="0.1" SmallChange="0.01" Margin="0,0,0,2"/>

                <TextBlock  Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right"
                    Text="Frame Interval"  Margin="0,0,10,0"
                    Style="{StaticResource KinectTextBlock}"
                    IsEnabled="{Binding Path=KinectSensorManager.CameraSettings.AutoExposure, Converter={StaticResource BoolToInverseBoolConverter}}"/>
                <Slider  Grid.Row="2" Grid.Column="1" VerticalAlignment="Center"
                    Minimum="{Binding Path=KinectSensorManager.CameraSettings.MinFrameInterval}"
                    Maximum="{Binding Path=KinectSensorManager.CameraSettings.MaxFrameInterval}"
                    Value="{Binding Path=KinectSensorManager.CameraSettings.FrameInterval}" Margin="0,0,0,2"
                    IsEnabled="{Binding Path=KinectSensorManager.CameraSettings.AutoExposure, Converter={StaticResource BoolToInverseBoolConverter}}"/>

                <TextBlock  Grid.Row="3" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right"
                    Text="Exposure Time"  Margin="0,0,10,0"
                    Style="{StaticResource KinectTextBlock}"
                    IsEnabled="{Binding Path=KinectSensorManager.CameraSettings.AutoExposure, Converter={StaticResource BoolToInverseBoolConverter}}"/>
                <Slider  Grid.Row="3" Grid.Column="1" VerticalAlignment="Center" Margin="0,0,0,2"
                    Minimum="{Binding Path=KinectSensorManager.CameraSettings.MinExposureTime}"
                    Maximum="{Binding Path=KinectSensorManager.CameraSettings.MaxExposureTime}"
                    Value="{Binding Path=KinectSensorManager.CameraSettings.ExposureTime}"
                    IsEnabled="{Binding Path=KinectSensorManager.CameraSettings.AutoExposure, Converter={StaticResource BoolToInverseBoolConverter}}"/>

                <TextBlock  Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right"
                    Text="Gain"  Margin="0,0,10,0"
                    Style="{StaticResource KinectTextBlock}"
                    IsEnabled="{Binding Path=KinectSensorManager.CameraSettings.AutoExposure, Converter={StaticResource BoolToInverseBoolConverter}}"/>
                <Slider Grid.Row="4" Grid.Column="1" VerticalAlignment="Center" Margin="0,0,0,2"
                    Minimum="{Binding Path=KinectSensorManager.CameraSettings.MinGain}"
                    Maximum="{Binding Path=KinectSensorManager.CameraSettings.MaxGain}"
                    Value="{Binding Path=KinectSensorManager.CameraSettings.Gain}"
                    IsEnabled="{Binding Path=KinectSensorManager.CameraSettings.AutoExposure, Converter={StaticResource BoolToInverseBoolConverter}}"/>

                <TextBlock  Grid.Row="5" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Right"
                    Text="Power Line Frequency"  Margin="0,0,10,0"
                    Style="{StaticResource KinectTextBlock}" TextWrapping="Wrap"
                    IsEnabled="{Binding Path=KinectSensorManager.CameraSettings.AutoExposure}"/>
                <ListBox Grid.Row="5" Grid.Column="1" VerticalAlignment="Center"
                    Style="{StaticResource KinectRadioList}"
                    ItemsSource="{Binding PowerLineFrequencyStates}"
                    IsEnabled="{Binding Path=KinectSensorManager.CameraSettings.AutoExposure}"
                    SelectedItem="{Binding Path=KinectSensorManager.CameraSettings.PowerLineFrequency}"/>

                <TextBlock  Grid.Row="6" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Right"
                    Text="Backlight Compensation Mode"  Margin="0,0,10,0" TextWrapping="Wrap"
                    Style="{StaticResource KinectTextBlock}"
                    IsEnabled="{Binding Path=KinectSensorManager.CameraSettings.AutoExposure}"/>
                <ListBox Grid.Row="6" Grid.Column="1" VerticalAlignment="Center"
                    Style="{StaticResource KinectRadioList}"
                    ItemsSource="{Binding BacklightCompensationModeStates}"
                    SelectedItem="{Binding Path=KinectSensorManager.CameraSettings.BacklightCompensationMode}"
                    IsEnabled="{Binding Path=KinectSensorManager.CameraSettings.AutoExposure}"/>

                <Button Click="ResetExposure" Grid.ColumnSpan="2" Grid.Row="7" Style="{StaticResource KinectButton}" Width="Auto">
                    Reset Exposure Settings
                </Button>
            </Grid>
        </RadioButton>

        <RadioButton Tag="C_olor Settings" Style="{StaticResource KinectSettingsPanel}" Margin="0 0 0 10"
                     Visibility="{Binding Path=KinectSensorManager.SupportsCameraSettings, Converter={StaticResource BoolToVisibilityConverter}}">
            <Grid Width="220">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>

                <TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right"
                    Text="Auto White Balance"  Margin="0,0,10,0" TextWrapping="Wrap"
                    Style="{StaticResource KinectTextBlock}"/>
                <ListBox Grid.Row="0" Grid.Column="1"
                    Style="{StaticResource KinectRadioList}"
                    ItemsSource="{Binding ToggleStates}" 
                    SelectedItem="{Binding Path=KinectSensorManager.CameraSettings.AutoWhiteBalance, Converter={StaticResource BoolToToggleStateConverter}}"/>
                
                <TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right"
                    Text="White Balance" Margin="0,0,10,0"
                    Style="{StaticResource KinectTextBlock}"
                    IsEnabled="{Binding Path=KinectSensorManager.CameraSettings.AutoWhiteBalance, Converter={StaticResource BoolToInverseBoolConverter}}"/>
                <Slider Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" Margin="0,0,0,2"
                    Minimum="{Binding Path=KinectSensorManager.CameraSettings.MinWhiteBalance}"
                    Maximum="{Binding Path=KinectSensorManager.CameraSettings.MaxWhiteBalance}"
                    Value="{Binding Path=KinectSensorManager.CameraSettings.WhiteBalance}"
                    IsEnabled="{Binding Path=KinectSensorManager.CameraSettings.AutoWhiteBalance, Converter={StaticResource BoolToInverseBoolConverter}}"/>

                <TextBlock Margin="0,0,10,0" Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right"
                    Text="Contrast" 
                    Style="{StaticResource KinectTextBlock}"/>
                <Slider Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" Margin="0,0,0,2"
                    Minimum="{Binding Path=KinectSensorManager.CameraSettings.MinContrast}"
                    Maximum="{Binding Path=KinectSensorManager.CameraSettings.MaxContrast}"
                    Value="{Binding Path=KinectSensorManager.CameraSettings.Contrast}"/>

                <TextBlock Margin="0,0,10,0" Grid.Row="3" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right"
                    Text="Hue" 
                    Style="{StaticResource KinectTextBlock}"/>
                <Slider Grid.Row="3" Grid.Column="1" VerticalAlignment="Center" Margin="0,0,0,2"
                    Minimum="{Binding Path=KinectSensorManager.CameraSettings.MinHue}"
                    Maximum="{Binding Path=KinectSensorManager.CameraSettings.MaxHue}"
                    Value="{Binding Path=KinectSensorManager.CameraSettings.Hue}"/>

                <TextBlock Margin="0,0,10,0" Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right"
                    Text="Saturation" 
                    Style="{StaticResource KinectTextBlock}"/>
                <Slider  Grid.Row="4" Grid.Column="1" VerticalAlignment="Center" Margin="0,0,0,2"
                    Minimum="{Binding Path=KinectSensorManager.CameraSettings.MinSaturation}"
                    Maximum="{Binding Path=KinectSensorManager.CameraSettings.MaxSaturation}"
                    Value="{Binding Path=KinectSensorManager.CameraSettings.Saturation}"/>

                <TextBlock Margin="0,0,10,0" Grid.Row="5" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right"
                    Text="Gamma" 
                    Style="{StaticResource KinectTextBlock}"/>
                <Slider  Grid.Row="5" Grid.Column="1" VerticalAlignment="Center" Margin="0,0,0,2"
                    Minimum="{Binding Path=KinectSensorManager.CameraSettings.MinGamma}"
                    Maximum="{Binding Path=KinectSensorManager.CameraSettings.MaxGamma}"
                    Value="{Binding Path=KinectSensorManager.CameraSettings.Gamma}"/>

                <TextBlock Margin="0,0,10,0" Grid.Row="6" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right"
                    Text="Sharpness" 
                    Style="{StaticResource KinectTextBlock}"/>
                <Slider Grid.Row="6" Grid.Column="1" VerticalAlignment="Center" Margin="0,0,0,2"
                    Minimum="{Binding Path=KinectSensorManager.CameraSettings.MinSharpness}"
                    Maximum="{Binding Path=KinectSensorManager.CameraSettings.MaxSharpness}"
                    Value="{Binding Path=KinectSensorManager.CameraSettings.Sharpness}"/>

                <Button Click="ResetColor" Grid.ColumnSpan="2" Grid.Row="7" Style="{StaticResource KinectButton}" Width="Auto">
                    Reset Color Settings
                </Button>
            </Grid>
        </RadioButton>

        <RadioButton Tag="_Depth Stream" Style="{StaticResource KinectSettingsPanel}" Margin="0 0 0 10">
            <StackPanel Orientation="Vertical" >
                <ListBox
                    Style="{StaticResource KinectRadioList}"
                    ItemsSource="{Binding DepthModes}"
                    SelectedItem="{Binding SelectedDepthMode}"/>
                <Label Content="Range" Style="{StaticResource KinectLabel}"/>
                <ListBox
                    Style="{StaticResource KinectRadioList}"
                    ItemsSource="{Binding DepthRanges}"
                    SelectedItem="{Binding Path=KinectSensorManager.DepthRange}"/>
                <Label Content="Depth Treatment" Style="{StaticResource KinectLabel}"/>
                <ListBox
                    Style="{StaticResource KinectRadioList}"
                    ItemsSource="{Binding DepthTreatments}"
                    SelectedItem="{Binding SelectedDepthTreatment}"/>
            </StackPanel>
        </RadioButton>

        <RadioButton Tag="S_keleton Stream"  Style="{StaticResource KinectSettingsPanel}" Margin="0 0 0 10">
            <StackPanel Orientation="Vertical" >
                <ListBox
                    Style="{StaticResource KinectRadioList}"
                    VerticalAlignment="Center"
                    ItemsSource="{Binding SkeletonModes}"
                    SelectedItem="{Binding SelectedSkeletonMode}"/>
                <Label Content="Chooser Mode" Style="{StaticResource KinectLabel}"/>
                <ListBox
                    Style="{StaticResource KinectRadioList}"
                    VerticalAlignment="Center"
                    ItemsSource="{Binding SkeletonChooserModes}"
                    SelectedItem="{Binding ElementName=SkeletonChooser, Path=SkeletonChooserMode}"/>
            </StackPanel>
        </RadioButton>

        <RadioButton Tag="_Sensor Settings"  Style="{StaticResource KinectSettingsPanel}" Margin="0 0 0 10">
            <StackPanel Orientation="Vertical">
                <Label Content="Tilt Angle" Style="{StaticResource KinectLabel}"/>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Label Grid.Row="0" Grid.Column="0" Style="{StaticResource KinectLabel}" HorizontalAlignment="Right">27°</Label>
                    <Image Grid.Row="1" Grid.Column="0" Width="50" Source="Images\KinectTilt.png" Margin="5"/>
                    <Label Grid.Row="2" Grid.Column="0" Style="{StaticResource KinectLabel}" HorizontalAlignment="Right">-27°</Label>

                    <Image Name="SliderTrack" Grid.Row="0" Grid.RowSpan="3" Grid.Column="1" Source="Images\SliderTrack.png" Margin="5 5 20 5"/>
                    <Image Grid.Row="0" Grid.RowSpan="3"  Grid.Column="1" Source="Images\Slider.png" Width="40" VerticalAlignment="Center" HorizontalAlignment="Right" RenderTransformOrigin="-1.3,0.5" MouseDown="Slider_MouseDown" MouseUp="Slider_MouseUp" MouseMove="Slider_MouseMove">
                        <Image.RenderTransform>
                            <RotateTransform  Angle="{Binding Path=KinectSensorManager.ElevationAngle, Converter={StaticResource DoubleScalerConverter}, ConverterParameter=-1.5}"/>
                        </Image.RenderTransform>
                    </Image>

                    <TextBlock Style="{StaticResource KinectTextBlock}" Grid.Row="0" Grid.RowSpan="3" Grid.Column="2" VerticalAlignment="Center" FontSize="{StaticResource LabelFontSize}" Text="{Binding Path=KinectSensorManager.ElevationAngle, StringFormat={}{0:F0}°}"/>
                </Grid>

                <Label Content="Infrared Emitter" Style="{StaticResource KinectLabel}"/>
                <CheckBox
                    Content="Force Off"
                    Style="{StaticResource KinectCheckBox}"
                    IsChecked="{Binding KinectSensorManager.ForceInfraredEmitterOff}"/>
            </StackPanel>
        </RadioButton>

        <RadioButton Tag="_Accelerometer" Style="{StaticResource KinectSettingsPanel}" IsChecked="{Binding Path=KinectSensorManager.EnableAccelerometerReading}" Margin="0 0 0 10">
            <StackPanel Orientation="Vertical">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>

                    <TextBlock Style="{StaticResource KinectTextBlock}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" Margin="5">x: </TextBlock>
                    <TextBlock Style="{StaticResource KinectTextBlock}" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" Margin="5">y: </TextBlock>
                    <TextBlock Style="{StaticResource KinectTextBlock}" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" Margin="5">z: </TextBlock>

                    <TextBlock Style="{StaticResource KinectTextBlock}" Grid.Row="0" Grid.Column="1" Margin="5" VerticalAlignment="Center" Text="{Binding Path=KinectSensorManager.Accelerometer.X, StringFormat={}{0:F2} g}"/>
                    <TextBlock Style="{StaticResource KinectTextBlock}" Grid.Row="1" Grid.Column="1" Margin="5" VerticalAlignment="Center" Text="{Binding Path=KinectSensorManager.Accelerometer.Y, StringFormat={}{0:F2} g}"/>
                    <TextBlock Style="{StaticResource KinectTextBlock}" Grid.Row="2" Grid.Column="1" Margin="5" VerticalAlignment="Center" Text="{Binding Path=KinectSensorManager.Accelerometer.Z, StringFormat={}{0:F2} g}"/>
                </Grid>
            </StackPanel>
        </RadioButton>
    </StackPanel>
</kt:KinectControl>
